package com.example.content_server.provider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.util.Log;

import com.example.content_server.database.UserDbHelper;

public class UserInfoProvider extends ContentProvider {
    private UserDbHelper dbHelper;

    @Override
    public boolean onCreate() {
        dbHelper = UserDbHelper.getInstance(getContext());
        return true;
    }

    /**
      *
      * @description 添加数据
      * @param
      * @return
      * author snjgm
      * time 2022/7/19 下午5:55
      */
    @Override
//    com.example.content_server.provider.UserInfoProvider
    public Uri insert(Uri uri, ContentValues values) {
        Log.d("ning","UserInfoProvider insert");
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        db.insert(UserDbHelper.TABLE_NAME,null,values);
        return uri;
    }

    /**
      *
      * @description 查询数据
      * @param 
      * @return 
      * author snjgm
      * time 2022/7/19 下午5:56
      */
    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
                        String[] selectionArgs, String sortOrder) {
        Log.d("TAG","UserInfoProvider query");
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        return db.query(UserDbHelper.TABLE_NAME, projection, selection, selectionArgs, null, null, null);
    }


    public UserInfoProvider() {

    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        // Implement this to handle requests to delete one or more rows.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public String getType(Uri uri) {
        // TODO: Implement this to handle requests for the MIME type of the data
        // at the given URI.
        throw new UnsupportedOperationException("Not yet implemented");
    }


    @Override
    public int update(Uri uri, ContentValues values, String selection,
                      String[] selectionArgs) {
        // TODO: Implement this to handle requests to update one or more rows.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}